package BUCF;

import java.util.Set;

import com.travel.core.AbstractDao;

public class similarity {
    private String user1, user2;

    public similarity() {
    }

    public similarity(String user1, String user2) {
        this.user1 = user1;
        this.user2 = user2;
    }

    // 计算Jaccard相似度
    public double computeSimilarity() {
        // Set<String> user1RatedSpot=JdbcUtils.getRatedItems(user1);
        Set<String> allRatedSpot = AbstractDao.getAllRatedItems(user1, user2);
        Set<String> commonRatedSpot = AbstractDao.getCommonRatedItems(user1, user2);// 交集
        // int num1=user1RatedSpot.size();
        // int num2=user2RatedSpot.size();
        // System.out.println(num1+" "+num2);
        int all = allRatedSpot.size();
        int common = commonRatedSpot.size();
        // System.out.println(common);
        return ((double) common) / all;
    }

    // 测试
    public static void main(String[] args) {
        double simi = new similarity("17428445", "35732914").computeSimilarity();
        System.out.println(simi);
    }
}
